﻿

using OpenCvSharp;

using System;
using System.Collections.Generic;

using Xc.DataAccess.CodeReader.Properties;
using Xc.DataAccess.Core;

namespace Xc.DataAccess.CodeReader.Models.Filters
{
    /// <summary>
    /// 绘制方框
    /// </summary>
    [Filter("绘制外边框",FilterType.Draw)]
    public class DrawContours : FilterBase
    {
        /// <summary>
        /// 坐标点
        /// </summary>
        [InputParameter("坐标点")]
        public List<Point[]> Points { get; set; } = new List<Point[]>();
        /// <summary>
        /// 轮廓参数
        /// </summary>
        [InputParameter("轮廓参数")]
        public int ContourIdx { get; set; }
        /// <summary>
        /// 颜色
        /// </summary>
        [InputParameter("颜色")]
        public Scalar Color { get; set; }
        /// <summary>
        /// 线条类型
        /// </summary>
        [InputParameter("线条类型")]
        public LineTypes LineTypes { get; set; } = LineTypes.Link8;
        /// <summary>
        /// 粗细
        /// </summary>
        [InputParameter("粗细",ParameterType.Optional)]
        public int Thickness { get; set; } = 1;
        /// <summary>
        /// 绘制等级
        /// </summary>
        [InputParameter("绘制等级",ParameterType.Optional)]
        public IEnumerable<HierarchyIndex> HierarchyIndices { get; set; }
        /// <summary>
        /// 最大等级
        /// </summary>
        [InputParameter("最大等级",ParameterType.Optional)]
        public int MaxLevel { get; set; } = int.MaxValue;
        /// <summary>
        /// 便宜量
        /// </summary>
        [InputParameter("偏移量", ParameterType.Optional)]
        public CVPoint Offset { get; set; } = new CVPoint();
        internal override ResultData<Mat> UseChannel(Mat mat, FilterBase[] filterBases, FilterBase preFilterBase)
        {
            Cv2.DrawContours(mat, Points, ContourIdx, Color, Thickness, LineTypes, HierarchyIndices, MaxLevel, Offset);
            return ResultData<Mat>.Accept(TextResource.drawing_text_success, mat);
        }
    }
}
